package com.autonavi.yunda.yunji.core.utils.datahub;

public enum SqlOperator {
    /**
     * 且
     */
    and("and", "and", false),
    and_("&&", "and", false),
    /**
     * 或
     */
    or("or", "or", false),
    or_("||", "or", false),
    /**
     * 等于
     */
    equal("equal", "=", false),
    equal_("=", "=", false),
    not_equal("not_equal", "<>", false),
    not_equal_("<>", "<>", false),
    /**
     * 大于
     */
    greater("greater", ">", true),
    greater_(">", ">", true),
    /**
     * 大于等于
     */
    greater_equal("greater_equal", ">=", true),
    greater_equal_(">=", ">=", true),
    /**
     * 小于
     */
    less("less", "<", true),
    less_("<", "<", true),
    /**
     * 小于等于
     */
    less_equal("less_equal", "<=", true),
    less_equal_("<=", "<=", true),
    /**
     * in |分割
     */
    in("in", "in", false),
    /**
     * 不加%的like
     */
    like_any("like_any", "~*", false),
    /**
     * 包含
     */
    include("include", "like", false),
    include_("like", "like", false),

    /**
     * 前缀匹配
     */
    start_with("start_with", "like", false),

    /**
     * 不包含
     */
    exclude("exclude", "not like", false),
    exclude_("not_like", "not like", false);
    //逻辑操作, 可选equal,=,not_equal,<>,greater,>,greater_equal,>=,less,<,less_equal,<=,in,like_any,like,not_like
    private String text;
    private String sql;
    private boolean isNumberic;

    SqlOperator(String text, String sql, boolean isNumberic) {
        this.text = text;
        this.sql = sql;
        this.isNumberic = isNumberic;
    }

    public String getText() {
        return text;
    }

    public String getSql() {
        return sql;
    }

    public boolean needPercent() {
        return include.equals(this) || include_.equals(this) || exclude.equals(this) || exclude_.equals(this);
    }

    public static SqlOperator judge(String source) {
        for (SqlOperator s : SqlOperator.values()) {
            if (s.getText().equals(source)) {
                return s;
            }
        }
        return null;
    }

    public static String translateToSql(String source) {
        for (SqlOperator s : SqlOperator.values()) {
            if (s.getText().equals(source)) {
                return s.getSql();
            }
        }
        return "";
    }

    public static boolean isNumeric(String source) {
        for (SqlOperator s : SqlOperator.values()) {
            if (s.getText().equals(source)) {
                return s.isNumberic();
            }
        }
        return false;
    }

    public boolean isNumberic() {
        return isNumberic;
    }
}
